*** Settings ***
Resource          ../test.robot

*** Test Cases ***
Login
    Evaluate    reload(sys)    modules=sys
    Evaluate    sys.setdefaultencoding("utf-8")    modules=sys
    ${token}    input token use dialog
    Comment    ${token}    Set Variable    输入6位token
    login use token    ${jump_host}    ${jump_user}    ${login_ip}    ${login_user}    ${login_pwd}    ${login_pin}${token}    dir_deploy=${dir_deploy}
    Comment    set use python    python2
    Comment    set prompt    ]#
    Comment    login normal    ${login_ip}    ${login_user}    ${login_pwd}    dir_deploy=${dir_deploy}
    [Teardown]    Run Keyword If Test Failed    Fatal Error

Clean
    clean    ip_list=${ip_list}
    [Teardown]    Run Keyword If Test Failed    Fatal Error

Install FISCO-BCOS
    Run Keyword If    ${fisco_install_flag} == 1    install fisco bcos    install_flag=1    git_branch=${fisco_branch}
    Run Keyword If    ${fisco_install_flag} == 2    install fisco bcos    install_flag=2    git_branch=${fisco_branch}
    Run Keyword If    ${fisco_install_flag} == 3    install fisco bcos    install_flag=3    release_version=${release_version}
    Comment    Run Keyword If    ${fisco_install_flag} == 3    install fisco bcos    install_flag=3    git_branch=${fisco_branch}
    Run Keyword If    ${fisco_install_flag} == 4    install fisco bcos    install_flag=4    remote=${remote_fisco}
    [Teardown]    Run Keyword If Test Failed    Fatal Error

Create node
    build chain    ipconf=${ip_conf}    ext=${build_chain_ext}
    [Teardown]    Run Keyword If Test Failed    Fatal Error

Transfer node
    trans node    ip_list=${ip_list}
    [Teardown]    Run Keyword If Test Failed    Fatal Error

Start node
    start node    ip_list=${ip_list}
    [Teardown]    Run Keyword If Test Failed    Fatal Error

Check node log
    Sleep    6
    ${check_log_rst}    check log    ext=${check_log_g1}
    Should Be True    ${check_log_rst}[0]
    ${check_log_rst}    check log    ip_list=${ip_list}    ext=${check_log_g1}
    Should Be True    ${check_log_rst}[0]
    [Teardown]    Run Keyword If Test Failed    Fatal Error

Install console
    install console    git_branch=master    remote=${remote_console}
    [Teardown]    Run Keyword If Test Failed    Fatal Error

Install java-sdk-demo
    install java sdk demo    git_branch=main    remote=${remote_java_sdk_demo}
    [Teardown]    Run Keyword If Test Failed    Fatal Error

Install python sdk
    install python sdk    git_branch=${python_sdk_branch}    remote=${remote_python_sdk}
    [Teardown]    Run Keyword If Test Failed    Fatal Error

Execute console
    execute console command    ${comm_deploy}
    execute console command    getBlockNumber->v_block_num=output
    execute console command    getBlockByNumber var{v_block_num}->trans_hash=self.use_key(output,"value")[0].replace("'","")
    ${help_info}    execute console command    -h
    Should Contain    ${help_info}    addObserver
    [Teardown]    Run Keyword If Test Failed    Fatal Error

Create account p12&pem
    log    Create pem account
    execute linux command    bash get_account.sh->v_pri_key_pem=self.get_account(output,2)    exec_dir=${dir_console}/dist
    log    Create p12 account
    execute linux command    bash get_account.sh -p->v_pri_key_p12=self.get_account(output,2)    exec_dir=${dir_console}/dist    interact_input=Password:,123456|Password:,123456
    [Teardown]    Run Keyword If Test Failed    Fatal Error

Execute press use java sdk
    Comment    ${press_out_put}    execute linux command    ${comm_press}
    Comment    Should Contain    ${press_out_put}    Error rate: 0.0%
    execute linux command    ${comm_press}    exec_dir=${dir_java_sdk_demo}/dist    loop_times=2
    [Teardown]    Run Keyword If Test Failed    Fatal Error

Execute curl
    execute linux command    ${comm_curl}
    [Teardown]    Run Keyword If Test Failed    Fatal Error

Execute python sdk
    Execute Linux Command    cd ${dir_python_sdk} && source ~/.bashrc && pyenv activate python-sdk
    Execute Linux Command    ./console.py deploy HelloWorld->v_py_contract_addr=self.use_key(output,"contractAddress")[0].replace(",","").replace('"','')
    Execute Linux Command    ./console.py getBlockNumber->v_py_bn=self.row_num(output,4,2)
    [Teardown]    Run Keyword If Test Failed    Fatal Error

Operate autotest ini
    opt autotest ini    set    tmp    mark
    ${a}    opt autotest ini    get    tmp
    log    ${a}
    opt autotest ini    del    tmp
    [Teardown]    Run Keyword If Test Failed    Fatal Error

Operate fisco-bcos ini on linux
    opt cfg for fisco bcos    ${dir_console}/dist/conf/config.toml    set    cryptoMaterial    tmp    \\"test1\\"
    ${a}    opt cfg for fisco bcos    ${dir_console}/dist/conf/config.toml    get    cryptoMaterial    tmp
    log    ${a}
    opt cfg for fisco bcos    ${dir_console}/dist/conf/config.toml    del    cryptoMaterial    tmp
    [Teardown]    Run Keyword If Test Failed    Fatal Error

Execute select for mysql
    ${sel_rst}    execute mysql    ${mysql_info}    select * from test where name='mark';
    log    ${sel_rst}
    ${sel_rst}    execute mysql    ${mysql_info}    select * from test where name="mark";
    log    ${sel_rst}
    Comment    ${sel_rst}    execute mysql    ${mysql_info}    select * from test where name="中文";
    Comment    Should Be Equal    ${sel_rst}    aaa|11!mark|35!
    [Teardown]    Run Keyword If Test Failed    Fatal Error

Close connection
    close autotest connection
